#define  _CRT_SECURE_NO_WARNINGS\

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>


int sushu(int n)
{
	int i = 0, flag = 1;
	for (i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0)
			flag = 0;
	}
	return flag;
}
int huiwen(int n)
{
	int temp = n, x = 0, y = 0;
	while (temp)
	{
		x = temp % 10;
		y = y * 10 + x;
		temp /= 10;
	}
	return y;
}
int main()
{
	int n = 0, i = 0, sum = 0;
	scanf("%d", &n);
	for (i = 11; i <= n; i++)
	{
		if (sushu(i) == 1 && huiwen(i) == i)
			sum++;
	}
	printf("%d\n", sum);
	return 0;
}